"""
@name : 4-1.process 进程创建
@author : wenyao
@projectname: sanchuanglianxi
"""
from multiprocessing import Process,current_process
import time
#
lst = []
def task(i):
    print(current_process().name, i, "start")
    lst.append(i)
    time.sleep(20)
    print(lst)
    print(i,"process end")
#
# if __name__ == "__main__":
#     #多进程建议设置与cpu核数一致
#     for i in range(4):
#         p = Process(target = task, args=(i,) )
#         p.start()

#各个进程拥有一份数据，隔离。

#类创建：
#继承process  重写run方法
class NewProcess(Process):
    def __init__(self, func, args=()):
        super().__init__()
        self.func = func
        self.args = args

    def run(self):
        self.func(*self.args)

if __name__ == "__main__":
    for i in range(4):
        p = NewProcess(task,args = (i,))
        #lst.append(p)
        p.start()

